home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-2.iso / extra / disp186b.zip / ATIULTRA.ASM < prev    next >
Assembly Source File  |  1994-02-23  |  13KB  |  453 lines

  1. ;--------------------------------------------------------------------------
  2. ; This is file ATIULTRA.ASM
  3. ;
  4. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5. ; Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6. ;
  7. ; This file is distributed under the terms listed in the document
  8. ; "copying.dj", available from DJ Delorie at the address above.
  9. ; A copy of "copying.dj" should accompany this file; if not, a copy
  10. ; should be available from where this file was obtained.  This file
  11. ; may not be distributed without a verbatim copy of "copying.dj".
  12. ;
  13. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  14. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. ;--------------------------------------------------------------------------
  16.  
  17. _TEXT    segment byte public 'CODE'
  18. _TEXT    ends
  19. DGROUP  group    _TEXT,_DATA,_BSS
  20.     assume  cs:_TEXT,ds:DGROUP
  21. _DATA    segment word public 'DATA'
  22. d@    label    byte
  23. d@w    label    word
  24. _DATA    ends
  25. _BSS    segment word public 'BSS'
  26. b@    label    byte
  27. b@w    label    word
  28. _BSS    ends
  29. _TEXT    segment byte public 'CODE'
  30.     assume  cs:_TEXT,ds:DGROUP
  31.  
  32. include grdriver.inc
  33.  
  34. ;--------------------------------------------------------------------------
  35. ; DRIVER HEADER
  36. ;  The following entries MUST match the structure and constant
  37. ;  declarations in the file 'grdriver.h' of the GRX graphics library
  38. ;  The mode word should contain the following bitfields:
  39. ;     - the GRD_NEW_DRIVER bit set for any new format driver
  40. ;     - the adapter type field should be specified
  41. ;     - the memory size field should be specified
  42. ;     - the paging mode field should be specified
  43. ;  The mode set routine will OR in the plane bitfield as it will
  44. ;  change when different color number modes are requested.
  45. ;--------------------------------------------------------------------------
  46.  
  47.     dw    offset mode_set_routine
  48.     dw    offset paging_routine
  49. mode_W  dw    GRD_NEW_DRIVER+GRD_VGA+GRD_256K+GRD_RW_64K
  50. ;
  51. ; The 'def_xx' fields are filled in by go32 from the corresponding
  52. ; fields of the 'GO32' environment variable
  53. ;
  54. def_tw  dw    80        ; text width
  55. def_th  dw    25        ; text height
  56. def_gw  dw    640        ; graphics width
  57. def_gh  dw    480        ; graphics height
  58. def_nc  dw    16        ; graphics colors
  59.     dw    offset driver_init_routine
  60.     dw    offset text_mode_table
  61.     dw    offset graphics_mode_table
  62.  
  63. ;
  64. ; Biggest text and graphics sizes
  65. ;
  66. Max_TW  equ    132
  67. Max_TH  equ    44
  68. Max_GWn equ    800        ; non interlaced!!!
  69. Max_GHn equ    600
  70. Max_GW  equ    1024        ; may be interlaced
  71. Max_GH  equ    768
  72.  
  73.  
  74. ;--------------------------------------------------------------------------
  75. ; TABLE OF SUPPORTED TEXT MODES
  76. ;    - keep sorted by size
  77. ;    - end with an all 0 entry
  78. ;    - BIOS field = 0xff disables it
  79. ;    - fields:
  80. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  81. ;--------------------------------------------------------------------------
  82. text_mode_table        label word
  83.     dw    80,    25,    2,    007h +  00000h
  84.     dw    40,    25,    16,    001h +  00000h
  85.     dw    80,    25,    16,    003h +  00000h
  86.     dw    80,    28,    16,    003h +  00400h
  87.     dw    80,    50,    16,    003h +  00100h
  88.     dw    132,    25,    16,    023h +  00000h
  89.     dw    132,    28,    16,    023h +  00400h
  90.     dw    132,    44,    16,    033h +  00000h
  91.     dw    132,    50,    16,    023h +  00100h
  92.     dw    0,    0,    0,    000h +  00000h
  93.  
  94. ;--------------------------------------------------------------------------
  95. ; TABLE OF SUPPORTED GRAPHICS MODES
  96. ;    - keep sorted first by colors then by size
  97. ;    - end with an all 0 entry
  98. ;    - BIOS field = 0xff disables it
  99. ;    - fields:
  100. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  101. ;--------------------------------------------------------------------------
  102. graphics_mode_table    label word
  103.     dw    320,    200,    16,    00dh +  00000h
  104.     dw    640,    200,    16,    00eh +  00000h
  105.     dw    640,    350,    16,    010h +  00000h
  106.     dw    640,    480,    16,    012h +  00000h
  107.     dw    800,    600,    16,    054h +  00000h
  108.     dw    1024,    768,    16,    055h +  00000h
  109.     dw    320,    200,    256,    013h +  00000h
  110.     dw    640,    400,    256,    061h +  00000h
  111. begin_8514_modes    label word
  112.     dw    640,    480,    256,    000h +  00300h     ; use 8514 mode
  113.     dw    1024,    768,    256,    001h +  00300h     ; use 8514 mode
  114.     dw    0,    0,    0,    000h +  00000h
  115.  
  116. ;--------------------------------------------------------------------------
  117. ; TABLE OF SPECIAL SETUP PROCEDURES
  118. ;  You may need such procedures for:
  119. ;     -- reloading fonts on standard EGA or VGA for
  120. ;     higher resolution text modes
  121. ;     -- enable HiColor mode of some Super VGAs
  122. ;     -- Handle the parameter passing conventions of the VESA BIOS
  123. ;     -- put VGA into 256 color plane mode ("MODE X")
  124. ;     -- etc...
  125. ;  There should be one entry in the table for every non-zero
  126. ;  'setup_procedure_index' in the text and graphics mode tables.
  127. ;  The first entry in the table belongs to index 100h, and so on.
  128. ;  The special setup procedure is invoked via a near call.
  129. ;
  130. ;  Entry: DI=address of the mode record from the text or graphics
  131. ;      table to set up.
  132. ;
  133. ;  Exit:  Adapter configured
  134. ;      BX=driver mode word as it should be returned by the mode set
  135. ;         routine. Typically it involves picking up the mode word
  136. ;         from the header and OR-ing in the appropriate bitplane mode
  137. ;         bitfield. (This is not needed for text modes)
  138. ;      AX, CX, DX, SI can be trashed, PRESERVE DI!!!!
  139. ;
  140. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  141. ;--------------------------------------------------------------------------
  142. special_setup_table    label word
  143.     dw    offset  VGA_50row_mode_set
  144.     dw    offset  VGA_MODE_X_set
  145.     dw    offset  IBM_8514_mode_set
  146.     dw    offset  VGA_28row_mode_set
  147.  
  148. ;
  149. ; Routine to set up VGA 50 row mode
  150. ; interface is described above
  151. ;
  152. VGA_50row_mode_set    proc    near
  153.     call    near ptr disable_8514A
  154.     mov    ax,WORD PTR [di+6]    ; get base mode number
  155.     xor    ah,ah
  156.     int    10h
  157.     xor    bx,bx
  158.     mov    ax,1112h        ; load 8x8 font
  159.     int    10h
  160.     ret
  161. VGA_50row_mode_set    endp
  162.  
  163. ;
  164. ; Routine to set up VGA 28 row mode
  165. ; interface is described above
  166. ;
  167. VGA_28row_mode_set    proc    near
  168.     call    near ptr disable_8514A
  169.     mov    ax,WORD PTR [di+6]    ; get base mode number
  170.     xor    ah,ah
  171.     int    10h
  172.     xor    bx,bx
  173.     mov    ax,1111h        ; load 8x14 font
  174.     int    10h
  175.     ret
  176. VGA_28row_mode_set    endp
  177.  
  178. ;
  179. ; Routine to set up VGA 256 color plane mode ("MODE X")
  180. ; interface is described above
  181. ; TO BE COMPLETED
  182. ;
  183. VGA_MODE_X_set        proc    near
  184.     mov    bx,mode_W
  185.     or    bx,GRD_8_X_PLANES
  186.     ret
  187. VGA_MODE_X_set        endp
  188.  
  189. ;
  190. ; Routine to set up 8514A 256 color mode
  191. ; interface is described above
  192. ;
  193. IBM_8514_mode_set    proc    near
  194.     mov    al,BYTE PTR [di+6]
  195.     xor    ah,ah
  196.     push    ax
  197.     call    near ptr setup_8514A_256_color_mode
  198.     pop    ax
  199.     mov    bx,GRD_NEW_DRIVER+GRD_8514A+GRD_8_PLANES
  200.     ret
  201. IBM_8514_mode_set    endp
  202.  
  203.  
  204. ;--------------------------------------------------------------------------
  205. ; DRIVER INIT ROUTINE
  206. ;  called once after the driver is loaded
  207. ;  may do one or more of the followings:
  208. ;    - check for proper board type
  209. ;    - check amount of RAM on board, and:
  210. ;    -- update word in header to reflect correct amount
  211. ;    -- disable modes in the tables for which there is not enough RAM
  212. ;    - check for special equipment (HiColor DAC, etc...)
  213. ;
  214. ;  Entry: nothing
  215. ;
  216. ;  Exit:  AX=status:
  217. ;       non-zero: OK,
  218. ;       0: something went wrong (e.g. wrong adapter, etc..)
  219. ;      BX,CX,DX may be trashed
  220. ;
  221. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  222. ;--------------------------------------------------------------------------
  223. driver_init_routine    proc    far
  224.     push    ds
  225.     mov    ax,cs
  226.     mov    ds,ax
  227.     call    near ptr check_8514A    ; test for 8514A
  228.     or    ax,ax
  229.     jne    have_8514A
  230.     mov    bx,offset begin_8514_modes
  231.     mov    WORD PTR [bx+6],062h    ; use SVGA mode for 640x480x256
  232.     mov    WORD PTR [bx+14],0ffh    ; invalidate 1024x768x256
  233. have_8514A:
  234.     mov    ax,1
  235.     pop    ds
  236.     ret
  237. driver_init_routine    endp
  238.  
  239.  
  240. ;--------------------------------------------------------------------------
  241. ; MODE SET ROUTINE
  242. ;  sets up a text or graphics mode as close as possible to the one
  243. ;  reguested by the user with regard to number of colors and size.
  244. ;
  245. ;  Entry: AX=mode selection
  246. ;     0 = 80x25 text
  247. ;     1 = default text
  248. ;     2 = text CX cols by DX rows
  249. ;     3 = biggest text
  250. ;     4 = 320x200 graphics
  251. ;     5 = default graphics
  252. ;     6 = graphics CX width by DX height
  253. ;     7 = biggest non-interlaced graphics
  254. ;     8 = biggest graphics
  255. ;     9 = graphics BX colors, CX width by DX height
  256. ;
  257. ;  Exit: BX=driver mode flag
  258. ;     CX=width (in pixels or characters)
  259. ;     DX=height
  260. ;
  261. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  262. ;     YOU SHOULD NOT NEED TO CHANGE THIS ROUTINE AS IT IS PRETTY
  263. ;     MUCH TABLE DRIVEN
  264. ;--------------------------------------------------------------------------
  265. mode_set_routine    proc    far
  266.     push    ds
  267.     push    di
  268.     push    si
  269.     mov    si,cs
  270.     mov    ds,si
  271.     cmp    ax,9
  272.     jbe    DoIt
  273.     jmp    Exit
  274. DoIt:    add    ax,ax
  275.     mov    si,ax
  276.     jmp    WORD PTR mode_set_table[si]
  277. mode_set_table  label    word
  278.     dw    offset mode_0
  279.     dw    offset mode_1
  280.     dw    offset mode_2
  281.     dw    offset mode_3
  282.     dw    offset mode_4
  283.     dw    offset mode_5
  284.     dw    offset mode_6
  285.     dw    offset mode_7
  286.     dw    offset mode_8
  287.     dw    offset mode_9
  288. mode_0: mov    si,offset text_mode_table    ; 80x25 text
  289.     mov    bx,def_nc
  290.     mov    cx,80
  291.     mov    dx,25
  292.     jmp    Lookup
  293. mode_1: mov    si,offset text_mode_table    ; default text
  294.     mov    bx,def_nc
  295.     mov    cx,def_tw
  296.     mov    dx,def_th
  297.     jmp    Lookup
  298. mode_2: mov    si,offset text_mode_table    ; CX*DX text
  299.     mov    bx,def_nc
  300.     jmp    Lookup
  301. mode_3: mov    si,offset text_mode_table    ; biggest text
  302.     mov    bx,def_nc
  303.     mov    cx,Max_TW
  304.     mov    dx,Max_TH
  305.     jmp    Lookup
  306. mode_4: mov    si,offset graphics_mode_table    ; 320x200 graphics
  307.     mov    bx,def_nc
  308.     mov    cx,320
  309.     mov    dx,200
  310.     jmp    Lookup
  311. mode_5: mov    si,offset graphics_mode_table    ; default graphics
  312.     mov    bx,def_nc
  313.     mov    cx,def_gw
  314.     mov    dx,def_gh
  315.     jmp    Lookup
  316. mode_6: mov    si,offset graphics_mode_table    ; CX*DX graphics
  317.     mov    bx,def_nc
  318.     jmp    Lookup
  319. mode_7: mov    si,offset graphics_mode_table    ; biggest non-interlaced gr
  320.     mov    bx,def_nc
  321.     mov    cx,Max_GWn
  322.     mov    dx,Max_GHn
  323.     jmp    Lookup
  324. mode_8: mov    si,offset graphics_mode_table    ; biggest graphics
  325.     mov    bx,def_nc
  326.     mov    cx,Max_GW
  327.     mov    dx,Max_GH
  328.     jmp    Lookup
  329. mode_9: mov    si,offset graphics_mode_table    ; CX*DX graphics w/ BX colors
  330. ;
  331. ; At this point:
  332. ;   SI points to the table to search (text or graphics)
  333. ;   BX has colors
  334. ;   CX has width
  335. ;   DX has height
  336. ;
  337. Lookup: xor    ax,ax                ; last color number seen
  338. Find_C: cmp    [si+4],ax            ; last color number == this?
  339.     je    Same_C
  340.     jb    Prev_C                ; end of table -- use last color
  341.     cmp    BYTE PTR [si+6],0ffh        ; valid entry ?
  342.     je    Prev_C                ; not -- use last color
  343.     mov    ax,[si+4]            ; record color number
  344.     mov    di,si                ; start of entries w/ this color
  345.     cmp    ax,bx                ; enough colors ?
  346.     jae    Find_S
  347. Same_C: add    si,8
  348.     jmp    Find_C
  349. Prev_C: or    ax,ax                ; found any color at all?
  350.     je    Exit
  351. ;
  352. ; At this point:
  353. ;   DI points into the table to the first entry with the desired color
  354. ;      number (either it has enough colors or it is the highest color
  355. ;      number supported by the driver). Additionally, at least the
  356. ;      first (= smallest size) entry for this color is valid (has a
  357. ;      valid BIOS number).
  358. ;   AX has the color number adjusted for the driver
  359. ;   CX has width
  360. ;   DX has height
  361. ;
  362. Find_S: cmp    [di+4],ax            ; still the same color #?
  363.     jne    Prev_S
  364.     cmp    BYTE PTR [di+6],0ffh        ; valid entry ?
  365.     je    Prev_S
  366.     cmp    [di],cx
  367.     jb    Next_S
  368.     cmp    [di+2],dx
  369.     jae    GotIt
  370. Next_S: add    di,8
  371.     jmp    Find_S
  372. Prev_S: sub    di,8
  373. ;
  374. ; At this point:
  375. ;   DI points to the table entry we want to set up
  376. ;
  377. GotIt:  mov    ax,[di+6]            ; BIOS mode number
  378.     or    ah,ah                ; special ?
  379.     je    doBIOS
  380.     mov    al,ah
  381.     xor    ah,ah
  382.     dec    ax
  383.     add    ax,ax
  384.     mov    si,ax
  385.     call    WORD PTR special_setup_table[si]
  386.     jmp    RetVal
  387. doBIOS: push    ax                ; save BIOS mode #
  388.     call    near ptr disable_8514A
  389.     pop    ax
  390.     int    10h
  391.     mov    bx,GRD_1_PLANE
  392.     cmp    WORD PTR [di+4],2        ; 2 colors ?
  393.     je    doFLAG
  394.     mov    bx,GRD_4_PLANES
  395.     cmp    WORD PTR [di+4],16        ; 16 colors ?
  396.     je    doFLAG
  397.     mov    bx,GRD_8_PLANES
  398.     cmp    WORD PTR [di+4],256        ; 256 colors ?
  399.     je    doFLAG
  400.     mov    bx,GRD_16_PLANES
  401.     cmp    WORD PTR [di+4],32768        ; 32K colors ?
  402.     je    doFLAG
  403.     mov    bx,GRD_PLANE_MASK        ; something is wrong!!
  404. doFLAG: or    bx,mode_W
  405. RetVal: mov    cx,[di]
  406.     mov    dx,[di+2]
  407. Exit:    pop    si
  408.     pop    di
  409.     pop    ds
  410.     ret
  411. mode_set_routine    endp
  412.  
  413.  
  414. ;--------------------------------------------------------------------------
  415. ; PAGING ROUTINE
  416. ;
  417. ;  Entry: AH=read page
  418. ;      AL=write page
  419. ;
  420. ;  Exit: VGA configured.
  421. ;     AX,BX,CX,DX,SI,DI may be trashed
  422. ;
  423. ;  NOTE: This runs in protected mode!  Don't mess with the segment registers!
  424. ;     This code must be relocatable and may not reference any data!
  425. ;--------------------------------------------------------------------------
  426.     assume  ds:nothing, es:nothing
  427.  
  428. paging_routine  proc    far
  429.     and    ah,0fh        ; Read-plane on bits 7-6-5
  430.     ror    ah,1
  431.     ror    ah,1
  432.     ror    ah,1
  433.  
  434.     and    al,0fh        ; Write-plane on bits 3-2-1
  435.     shl    al,1
  436.  
  437.     or    ah,al        ; Combine Read and Write plane
  438.  
  439.     mov    dx,01ceh    ; ATI register
  440.     mov    al,0b2h        ; plane select
  441.     out    dx,ax
  442.     ret
  443. paging_routine  endp
  444.  
  445. _TEXT    ends
  446.  
  447.     extrn    setup_8514A_256_color_mode:near
  448.     extrn    disable_8514A:near
  449.     extrn    check_8514A:near
  450.  
  451.     end
  452.  
  453.